<?php
session_start();
if(isset($_SESSION['lang']))
    require_once "./language_files/delete_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/delete_en.php";
require_once 'functions.php';
if(isset($_POST['paper_id']) && isset($_POST['conference_id']))
{
    $paper_id_d=$_POST['paper_id'];
    $conference_id=$_POST['conference_id'];
    //opening connection
    // geting the version ID from Author's paper
    // getting the last version of te paper
    $version_id=mysql_query(
            "SELECT max(`version_id`)
            FROM version v
            WHERE v.`paper_id` =$paper_id_d") or die(mysql_error());
    $row=mysql_fetch_assoc($version_id);
    $versionid=$row["max(`version_id`)"];
    $date=date('Y-m-d');
    $today=date("Y-m-d H:i:s",strtotime($date));
    $query=mysql_query("SELECT `status`
           FROM `paper`p
           WHERE`paper_id`='$paper_id_d'");
    $myrow=mysql_fetch_assoc($query);
    $status=$myrow["status"];
    //getting the deadline
    $deadline=mysql_query("SELECT `rev_startDate`, rev_endDate
            From`conference`c
            Where c.conference_id='$conference_id'
            ") or die(mysql_error());
    $row1=mysql_fetch_assoc($deadline);
    $deadline_date=$row1["rev_startDate"];
    $dead=$row1["rev_endDate"];
    //updating table paper into deleted
    if($today < $deadline_date || $today > $dead)
    {//checking if the the author is deleting before the deadline
        if($status != "dismissed")
        {
            $query=mysql_query("Update `paper`p
                 SET `status` = 'deleted'
                 where p.`paper_id` = '$paper_id_d'
                ") or die(mysql_error());

            $query4=mysql_query("Update `paper`p
                 SET `deleted` = 1
                 where p.`paper_id` = '$paper_id_d'
                ") or die(mysql_error());
            echo $lang['message_1'];
        }
        else
        {
            echo $lang['message_2'];
        }
    }
    else
    {

        echo $lang['message_3'];
    }
    mysql_close();
}
?>